package comm

import "regexp"

type AdjustType int32

var StockCodePtn = regexp.MustCompile("^\\d{6}$")

const (
	// NoAdjust 不复权
	NoAdjust AdjustType = iota
	// 前复权
	PreAdjust
	// 后复权
	PostAdjust
)

// Exchange 交易所
type Exchange int32

const (
	SH Exchange = iota
	SZ
)

func ExchangeOf(code string) Exchange {
	if code[0] == '6' {
		return SH
	}
	return SZ
}

// Board 股票板块
type Board int32

const (
	SHA = Board(10)
	KCB = Board(12)
	SZA = Board(20)
	ZXB = Board(21)
	CYB = Board(22)
)

func BoardOf(code string) Board {
	if code[0:3] == "002" {
		return ZXB
	}
	if code[0:2] == "30" {
		return CYB
	}
	if code[0:2] == "00" {
		return SZA
	}
	if code[0:3] == "688" {
		return KCB
	}
	return SHA
}

// StockSymbol 将股票数字编码转换成带交易所代号的股票代码
func StockSymbol(code string) string {
	if code[0] > '9' || code[0] < '0' {
		return code
	} else if code[0] == '6' {
		return "SH" + code
	}
	return "SZ" + code
}

// StockCode 将带交易所代号的股票代码转换成股票数字编码
func StockCode(symbol string) string {
	return symbol[2:]
}
